﻿var mobile = "";
//表格的所有数据
var re_records = "";
$(function () {

    if (sessionStorage.getItem("isgroup") == "0" || sessionStorage.getItem("roleId") == "3") {

        $("#add").hide();
        //  $("#fs").hide();
        //
        // $("#delsb").hide();
    }
    if (sessionStorage.getItem("type") == "3") {
        $("#fs").hide();
    }
    $("#add").click(function (z) {
        // $("#user_name").attr("disabled",false);
        // $("#myModal").find("span").empty();      $("#myModal").find("input").val("");
        // $("#myModalLabel").text("新增");
        //mobile="";
        
        console.log(123);
        parent.addTabs({ id: '101', title: domain.language.$t('jiemu_tianjiajiemu'), close: true, url: '?#/page/Program/addtow' });
        // location.href="?#/page/Program/add";

    });
    //appvm.prompt();
    // domain.jsonthis.modify();
});


$(document).ready(function () {
    $.jgrid.defaults.styleUI = "Bootstrap";
    $("#table_list_1").jqGrid({
        data: [],
        datatype: "local",
        height: "100%",
        autowidth: true,
        shrinkToFit: true,
        rowNum: 20,
        rowList: [10, 20, 30, 60, 90, 100, 200, 500],
        //colNames: ["编号", "名称", "手机号码"],
        colModel: [{
            name: 'programid', index: 'programid', align: "center", width: 25, label: domain.language.$t('jiemu_bianhao'), align: 'center',
        },
        {
            name: 'company_id', index: 'company_id', align: "center", width: 25, label: "company_id", align: 'center', hidden: true,


        },

        {
            name: 'group_programid', index: 'group_programid', align: "center", width: 20, label: domain.language.$t('jiemu_jiemuhao'), align: 'center',
            formatter: function (value, options, row) {

                return parseInt(value) + 1;
            }
        },
        {
            name: 'festivalname', index: 'festivalname', align: "center", width: 34, label: domain.language.$t('admin.jiemu_jiemumingcheng'), align: 'center',
        },
        {
            name: 'type', index: 'type', align: "center", width: 23, label: domain.language.$t('jiemu_jiemuleix'), align: 'center',

            formatter: function (value, options, row) {

                return domain.language.$t('jiemu_jmlx'+value);
                // if (value == "0") {


                //     return "公益节目";

                // }

                // if (value == "1") {

                //     return "商业节目";
                // }

                // if (value == "2") {

                //     return "即时节目";
                // }

                // if (value == "3") {

                //     return "固定节目";
                // }

            }

        },
        {
            name: 'devicetype', index: 'devicetype', align: "center", width: 18, label: domain.language.$t('jiemu_shebieleixing'), align: 'center',
            formatter: function (value, options, row) {

                return domain.language.$t('jiemu_sblx'+value);
              
            }
        },

        {
            name: 'starttime', index: 'starttime', align: "center", width: 25, label: domain.language.$t('jiemu_bfkssj'), align: 'center',
            formatter: function (value, options, row) {

                if (typeof (value) != "undefined") {
                    try {
                        var date = new Date(value)

                        return date.Format("yyyy-MM-dd");
                    } catch (ex) {

                        console.log(ex);
                    }
                }
                return "";
            }
        },
        {
            name: 'endtime', index: 'endtime', align: "center", width: 25, label:  domain.language.$t('jiemu_bfjssj'), align: 'center',
            formatter: function (value, options, row) {

                if (typeof (value) != "undefined") {
                    try {
                        var date = new Date(value)

                        return date.Format("yyyy-MM-dd");
                    } catch (ex) {

                        console.log(ex);
                    }
                }
                return "";
            }
        },
        // {
        //   name: 'order_serialno', index: 'order_serialno',align:"center", width: 30, label: "订单号", align: 'center',
        // },
        {
            name: 'zeroindex', index: 'zeroindex', align: "center", width: 18, label: domain.language.$t('jiemu_fqsl'), align: 'center',
        },
        {
                        name: 'materialInfo', index: 'materialInfo', align: "center", width: 35, label: domain.language.$t('jiemu_jiemuneirong'), align: 'center',
                        formatter: function (value, options, row) {
                           if (typeof (value) != "undefined") {                 
            if(value.indexOf("|")!=-1){
                var valuece="";
                value=value.split('|');
                for(var i=0;i<value.length;i++){
                valuece+=domain.language.$t('jiemu_'+value[i].trim()).indexOf("jiemu_")==-1?domain.language.$t('jiemu_'+value[i].trim())+"|":value[i]+"|";
                }
                return valuece.substring(0, valuece.length - 1);
            }else{
                return domain.language.$t('jiemu_'+value.trim()).indexOf("jiemu_")==-1?domain.language.$t('jiemu_'+value.trim()):value;
            }
        }
         return "";
         }
          },
        {
            name: 'create_time', index: 'create_time', align: "center", width: 35, label: domain.language.$t('jiemu_shijian'), align: 'center',
            formatter: function (value, options, row) {

                if (typeof (value) != "undefined") {
                    try {
                        var date = new Date(value)

                        return date.Format("yyyy-MM-dd hh:mm:ss");
                    } catch (ex) {

                        console.log(ex);
                    }
                }
                return "";
            },
        },
        {
            name: 'permissions', index: 'permissions', width: 18, align: "center", label:domain.language.$t('jiemu_shenghezhuangtai'), align: 'center',
            formatter: function (value, options, row) {
                //console.log(options.rowId);
                var html = "";
                if (parseInt(value) == 1) {
                    
                    html = "<input type='hidden' class='permissions' value='" + value + "'><a style='color:green' data-target='#modalExamine'  data-toggle='modal' onclick=queryExamine('" + row.programid + "')>"+domain.language.$t('jiemu_shzt1')+"</a>";

                }
                if (parseInt(value) == 2) {
                    html = "<input type='hidden' class='permissions'value='" + value + "'><span style='color:blue'>"+domain.language.$t('jiemu_shzt2')+"</span>";
                }
                if (parseInt(value) == 3) {
                    html = "<input type='hidden' class='permissions' value='" + value + "'><a style='color:red' data-target='#modalExamine'  data-toggle='modal' onclick=queryExamine('" + row.programid + "')>"+domain.language.$t('jiemu_shzt3')+"</a>";
                } if (parseInt(value) == 4) {
                    html = "<input type='hidden' class='permissions' value='" + value + "'><a style='color:red' data-target='#modalExamine'  data-toggle='modal' onclick=queryExamine('" + row.programid + "')>"+domain.language.$t('jiemu_shzt4')+"</a>";
                }

                return html;
            }
        },
        {
            name: '', index: '', width: 17, align: "center", label: "设备状态", align: 'center', hidden: true,
            formatter: function (value, options, row) {
                //console.log(options.rowId);
                var html = "<a onclick=state('" + row.programid + "','" + row.devicetype + "');>查看</a>";
                return html;
            }
        },
        {
            name: 'cz', index: 'cz', width: 25, align: "center", label: domain.language.$t('jiemu_caozuo'), align: 'center',
            formatter: function (value, options, row) {
                var html = "";
                if (sessionStorage.getItem("roleId") == "3") {
                    html = "<button type='button'  class='btn btn-primary' onclick=modify('" + row.programid + "','" + row.group_programid + "');>查看节目</button>";

                } else {
                    html = "<button type='button'  class='btn btn-primary' onclick=modify('" + row.programid + "','" + row.group_programid + "');>"+domain.language.$t('jiemu_bianjijiemu')+"</button>";
                }
                return html;
            }
        },
        ],
        pager: "#pager_list_1",
        viewrecords: true,
        multiselect: true,
        caption: domain.language.$t('jiemu_jiemuliebiao'),
        hidegrid: false,
        ondblClickRow: function (row) {
            //双击一行触发的事件
            var rowDate = $("#table_list_1").jqGrid('getRowData', row);


            // $("#update").click();

            // console.log("节目编号"+ii.programid)
            // modify(rowDate.programid,parseInt(rowDate.group_programid)-1);



        },

        onPaging: function (pageBtn) {
            console.log(":" + pageBtn);
            //	    	var re_records = $jqgrid.getGridParam('records');//获取返回的记录数  
            var re_page = $("#table_list_1").getGridParam('page');//获取返回的当前页
            var re_rowNum = $("#table_list_1").getGridParam('rowNum');//获取每页数
            var re_total = $("#table_list_1").getGridParam('lastpage');//获取总页数
            //alert(re_total);

            if (pageBtn === "next") {
                // initJqgrid(re_page+1,re_rowNum);
                // if()
                pageval = pageval + 1;
                cxlist();
            }
            if (pageBtn === "prev") {

                pageval = pageval - 1; cxlist();
            }

            if (pageBtn == "last") {

                pageval = re_total;

                cxlist();

            }
            if (pageBtn == "first") {

                pageval = 1;

                cxlist();

            }

            if (pageBtn == "records") {

                sizeval = $(".ui-pg-selbox").val();
                pageval = 1;
                cxlist();
            }
        },
        // onSelectAll : function (rowids,status) {
        //     doSelect(rowids,status);
        // }, m



    });


    $(window).resize(function () {
        $("#table_list_1").setGridWidth($(window).width());
        $("#table_list_1").setGridHeight($(window).height() - 310);
        });
    for (var i = 1; i <= 225; i++) {

        $("#playcount").append("<option value='" + i + "'>" + i + "</option>");
    }
});
var sizeval = 20;
var pageval = 1;
var usernameval = $("#usnameval").val();
var conameval = "";
var json = "";


//节目不通过就不选中
// function doSelect(rowids,status) {



//     var allJQGridData = $('#table_list_1').jqGrid('getGridParam', 'data');
//     var ro="";
//     for (i = 1; i <= allJQGridData.length; i++) {      
//         ro = $("#table_list_1 #" + i + " .permissions").val();            
//         if (ro!=1){

//             $("#table_list_1").jqGrid('setSelection', i, true);  //无法选中
//         }
// }

// }


window.cxlist = function () {

    domain.ajaxUrl({
        method: 'POST',
        url: domain.testUrl + "/Threeinjection/programManagement/queryProgramInfolist",
        data: {
            size: sizeval, page: pageval, coid: sessionStorage.getItem("coid"),
            festivalname: $("#usnameval").val(), type: $("#type").val(), "audit": $("#examresult").val(), devicetype: $("#devicetype").val(), sessionid: sessionStorage.getItem("sid")
        },
        // datatype:"JSON",
        success: function (response) {

            // console.log(response);

            json = response;
            var data = JSON.parse(response);
            var reader = {
                root: function (obj) { return data.rows; },
                page: function (obj) { return pageval; },
                total: function (obj) { return data.taotal; },
                records: function (obj) {

                    return data.records;
                },

            };
            $("#table_list_1").setGridParam({ data: data.rows, localReader: reader }).trigger('reloadGrid');
            re_records = data.rows;

            if (re_records == "" || re_records == null) {
                if ($(".norecords").html() == null) {
                    $("#table_list_1").parent().append("<div class=\"norecords\">"+domain.language.$t('jiemu_meiyoufuheshuju')+"</div>");
                }
                $(".norecords").show();
            } else {

                $(".norecords").hide();
            }
            //隐藏修改
            if (sessionStorage.getItem("isgroup") == "0") {
                $("#table_list_1").hideCol("cz");
                $("#table_list_1").setGridWidth($(window).width());
            }

            var rowData = $('#table_list_1').jqGrid("getRowData");//所有行，数组

            var ro = "";
            var tab = "";
            for (var i = 0; i < rowData.length; i++) {
                var ii = i + 1;
                tab = $("#table_list_1 #" + ii);
                ro = $("#table_list_1 #" + ii + " .permissions").val();
                if (parseInt(ro) != 1) {

                    tab.css("background-color", "rgba(126, 128, 9, 0.1)");
                    //隐藏复选框
                    // $("#jqg_table_list_1_"+ii).attr("disabled","disabled");
                    // $("#jqg_table_list_1_"+ii).css("display","none");

                }
                else {
                    if (parseInt(sessionStorage.getItem("roleId")) == 2)
                        //审核通过不能修改
                        tab.find("td:last button").attr("disabled", "disabled");
                }

            }

            if (sessionStorage.getItem("isParent") != "true") {
                $(".ui-row-ltr").each(function () {
                    if ($(this).find("td").eq(2).text() !== sessionStorage.getItem("coid")) {
                        $(this).hide();
                    }
                });
            }

            $("#table_list_1").setGridHeight($(window).height() - 310);
            $("#table_list_1").setGridWidth($(window).width() - 3);
        }
    });
}

//加载审核内容
window.queryExamine = function (programId) {

    $.ajax({
        type: 'POST',
        url: domain.testUrl + "/Threeinjection/programManagement/queryAuditorInfo",
        data: { sessionid: sessionStorage.getItem("sid"), coid: sessionStorage.getItem("coid"), "programId": programId },
        success: function (response) {
            response = JSON.parse(response);
            console.log("数据" + response)

            if (response != "") {
                $("#numberNo").val(response[0].programId);
                $("#programNo").val(response[0].programNum);
                $("#programeName").val(response[0].programName);
                $("#examineMan").val(response[0].auditorName);
                $("#result").val(response[0].resultId);
                $("#reason").val(response[0].cause);

            } else { 
                $(".close").click(); 
                swal(domain.language.$t('jiemu_shehetishibiaoti'), domain.language.$t('jiemu_shehetishi'), "info");
            }
        }
    });


};

$(function () {

    if (sessionStorage.getItem("isgroup") == "1") {

        $("label").eq(2).hide(); $("#devicetype").hide();
    }

    $("button").eq(0).click(function () {
        

        cxlist();
    });
    cxlist();

});
Date.prototype.Format = function (fmt) {
    //author:wangweizhen
    var o = {
        "M+": this.getMonth() + 1,                 //月份   
        "d+": this.getDate(),                    //日
        "h+": this.getHours(),                   //小时   
        "m+": this.getMinutes(),                 //分   
        "s+": this.getSeconds(),                 //秒   
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度   
        "S": this.getMilliseconds()             //毫秒   
    };
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

window.modify = function (programid, group_programid) {
    // if(sessionStorage.getItem("isgroup")=="0"){
    //     swal("OMG!","请选择卡组","error");
    //     return false;
    // }
    //$("#static").val("1");
    sessionStorage.setItem("programid", programid);
    sessionStorage.setItem("group_programid", parseInt(group_programid) + 1);


    parent.Addtabs.close("tab_100");
    setTimeout(function () {
   parent.addTabs({ id: '100', title: domain.language.$t('jiemu_xiugaijiajiemu'), close: true, url: '?#/page/Program/edit' });
    },500);

   //parent.addTabs({ id: '100', title: '修改节目', close: true, url: '?#/page/Program/edit' });
    // setTimeout(function () {

    //     var id = parent.$("#tabSuperior").find(".active").find("a").attr("href");
    //     var id2 = id.split('_');

    //     //  alert(parent.$("#if"+parent.$("#tabSuperior").find(".active").find("a").attr("href")).html());
    //     //$("#if"+parent.$("#tabSuperior").find(".active").find("a").attr("href")).reload();
    //     //parent.id="tab_100";
    //     //parent.closeTab("tab_100");

    //     parent.Addtabs.add({ 'id': id2[1], 'url': parent.$(id).children("iframe").attr("src") });


    //     //parent.$("#tab_tab_100").find("a").find(".glyphicon-remove").click();
    //     //parent.$("#iftab_100").attr("src","?#/page/Program/edit");



    // }, 500);
    
    // domain.jsonthis.userinfo=[json.rows[i].user_name];

};

$(function () {
    var programidval = "";

    $("#del").click(function () {
        programidval = "";
        var ids = $("#table_list_1").jqGrid("getGridParam", "selarrrow");

        //遍历访问这个集合
        $(ids).each(function (index, id) {
            //由id获得对应数据行
            var row = $("#table_list_1").jqGrid('getRowData', id);
            programidval += row.programid + ","
            //console.log("row.ID:"+row.programid);
        });
        programidval = programidval.substring(0, programidval.length - 1);
        
        

        if (re_records == "" || re_records == null) {
            swal(domain.language.$t('jiemu_shehetishibiaoti'), domain.language.$t('jiemu_zwjmqxtj'), "info");
            return;
        } else {
            if (programidval == "") {
                
                swal("OMG!", domain.language.$t('jiemu_qxcxyscdjm'), "error");
                return;
            } else {
                var msg =  domain.language.$t('jiemu_qdscjmm');


                swal({
                    title: "",
                    text:msg,
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: domain.language.$t('queding'), 
                    cancelButtonText: domain.language.$t('guanbi'), 
                    closeOnConfirm: false
                },
                function (isConfirm) {
                    if(isConfirm){
                      //  top.swal.close();
                      $.ajax({
                        type: 'POST',
                        url: domain.testUrl + "/Threeinjection/programManagement/deleteProgramInfo",
                        data: { "programidList": programidval, sessionid: sessionStorage.getItem("sid") },

                        success: function (response) {
                            response = JSON.parse(response);
                            if (response.code == "200") {

                                pageval = 1;
                                cxlist();
                                swal("success!", domain.language.$t('jiemu_shangchuchenggong'), "success");
                                //刷新节目号:这个只能用来刷iframe,要找到iframe的id,tab就相当于iframe
                                parent.window.frames["iftab_101"].window.programlist();


                            }

                        }
                    });
                    }else{ programidval="";
                        top.swal.close()
                    }
                });
            }}
            });
          
    //             swal({
    //                 title: msg,
    //                 /* text: "删除之后无法恢复该数据!", */
    //                 type: 'warning',
    //                 showCancelButton: true,
    //                 confirmButtonColor: "#DD6B55",
    //                 confirmButtonText: domain.language.$t('queding'), 
    //                 cancelButtonText: "取消", 
    //                 closeOnConfirm: false
    //                 },
    //                 function (isConfirm) {
    //                     if(isConfirm){
       

    //           //  if (confirm(msg) == true) {
                  
    //                 return true;
    //             } else {
    //                 programidval="";
    //                 return false;
    //             }
    //         }
    //     }


    // });

    $("#delsb").click(function () {
        

        $("#sbfs").html(domain.language.$t('jiemu_queding'));



    });
    $("#fs").click(function () {


        $("#sbfs").html(domain.language.$t('jiemu_fasong'));



    });



    $("#sbfs").click(function () {
        //    $("#sbfs").html("发送");
        
        if ($("#sbfs").html() == domain.language.$t('jiemu_fasong')) {
            if ($("#device_id").val() == "" && $("#companyid").val() == "") {

                swal("OMG!", domain.language.$t('jiemu_qxzsbhdw'), "error");
                return false;

            } else {
                
                var rowData = $('#table_list_1').jqGrid('getGridParam', 'selarrrow');




                var programid = ""; var type = "";var ii=0;
                if (rowData.length) {
                    for (var i = 0; i < rowData.length; i++) {
                        programid += $('#table_list_1').jqGrid('getCell', rowData[i], 'programid') + ",";//name是colModel中的一属性

                        //if($('#table_list_1').jqGrid('getCell',rowData[i],'type')=="""")

                        var type1 = $('#table_list_1').jqGrid('getCell', rowData[i], 'devicetype');

                        if (type1 ==  domain.language.$t('jiemu_sblx0')) {

                            type = 0;
                        }
                        if (type1 ==  domain.language.$t('jiemu_sblx1')) {

                            type = 1;
                        }

                        if (type1 ==  domain.language.$t('jiemu_sblx2')) {

                            type = 2;
                        }




                        if (type1 ==  domain.language.$t('jiemu_sblx3')) {

                            type = 3;
                        }
                    }
                }
                programid = programid.substring(0, programid.length - 1);
                if (re_records == "" || re_records == null) {
                    swal(domain.language.$t('jiemu_shehetishibiaoti'), domain.language.$t('jiemu_zwjmqxtj'), "info");
                    return;
                } else {
                    if (programid == "") {
                        swal("OMG!", domain.language.$t('jiemu_qxxjmh'), "error");
                        return false;

                    } else {



                        var ids = $("#table_list_1").jqGrid("getGridParam", "selarrrow");
                        var ro = "";
                        var flag = true;
                        var zeroindex=0;
                        var num=0;
                        //遍历访问这个集合
                        $(ids).each(function (index, id) {

                            ro = $("#table_list_1 #" + id + " .permissions").val();
                            if (parseInt(ro) != 1) {
                                flag = false;domain.language.$t('jiemu_qxxjmh')
                                swal("OMG!",domain.language.$t('jiemu_jmwszqlxgyl'), "error");
                                return false;
                                
                            }
                            zeroindex= $('#table_list_1').jqGrid('getCell', ids[index], 'zeroindex');
                            num=$('#table_list_1').jqGrid('getCell', ids[index], 'group_programid');
                            if (parseInt(zeroindex)<=0) {
                                flag = false;
                              
                                swal("OMG!",   domain.language.$t('jiemu_fqbunwqxtjgwjm'), "error");
                                return false;

                            }
                            
                        });
                        //未审核跳出
                        if (flag == false) {
                            return false;
                        }

                        var coidval = $("#companyid").val();
                        if (coidval.indexOf(',') != -1) {
                            coidval = coidval.split(',')[0];
                        }


                        //if(programid.indexOf("3")!=-1){

                        // swal("OMG!", "安卓节目,目前不能发送", "error");
                        //return false;
                        // }
                        // type = type.substring(0, type.length-1);
                        // alert(type);
                        //return;


                        var timer = setInterval(function ()   //开启循环：每秒出现一次提示框
                        {
                            $("body").mLoading("show");
                        }, 500);


                        $.ajax({
                            type: 'POST',
                            url: domain.testUrl + "/Threeinjection/programManagement/sendProgramInfoToDeivce",
                            data: {
                                sessionid: sessionStorage.getItem("sid"), "programid": programid, type: $("#type_val").val(),
                                "devicenumber": $("#device_id").val(), companyid: coidval
                            },
                            sessionid: sessionStorage.getItem("sid"),
                            // timeout: 8000,//超时设置
                            // async:true,
                            success: function (response) {
                                response = JSON.parse(response);
                                if (response.code == "200") {
                                    clearInterval(timer);
                                   // ii++;
                                    // $(".mloading-mask").hide();
                                    $("body").mLoading("hide");
                                    //if (ii==1){ 
                                    swal("success!", domain.language.$t('jiemu_jmtjcgrxkdfsddqgzfsjjym'), "success");
                                    $(".close").click();
                                    
                                    cxlist();
                                   // }
                                } else {

                                    clearInterval(timer);
                                    // $(".mloading-mask").hide();
                                    $("body").mLoading("hide");
                                    swal("OMG!", domain.language.$t('jiemu_jiemutijiaoshib'), "error");
                                    

                                }
                            }, error: function (response, ajaxOptions, thrownError) {
                                
                                clearInterval(timer);

                                $("body").mLoading("hide")
                                swal("OMG!", domain.language.$t('jiemu_jiemutijiaoshib'), "error");
                            },
                            complete: function (XMLHttpRequest, status) {

                                if (status == 'timeout') {
                                    clearInterval(timer);
                                    $("body").mLoading("hide")

                                }
                            }

                        });
                    }
                }
            }

        } else {

            if ($("#device_id").val() == "" && $("#companyid").val() == "") {
               
                swal("OMG!",  domain.language.$t('jiemu_qxzsbhdw'), "error");
                return false;

            } else {

                var rowData = $('#table_list_1').jqGrid('getGridParam', 'selarrrow');
                if (re_records == "" || re_records == null) {
                    swal("提示", domain.language.$t('jiemu_zwjmqxtj'), "info");
                    return;
                } else { 
                    if (rowData == "") {
                        swal("OMG!", domain.language.$t('jiemu_qxxjmh'), "error");
                        return false;

                    } else {

        
                        var ro = "";
                        var flag = true;
                        //遍历访问这个集合
                        $(rowData).each(function (index, id) {

                            ro = $("#table_list_1 #" + id + " .permissions").val();
                            if (parseInt(ro) != 1) {
                                flag = false;
                                swal("OMG!",  domain.language.$t('jiemu_bqjmbnxj'), "error");
                                return false;

                            }
                        });
                        //未审核跳出
                        if (flag == false) {
                            return false;
                        }


                        var programid = new Array(); var type = "";var ii=0;
                        if (rowData.length>0) {
                            // sessionStorage.setItem("xiajia", "one");
                            for (var i = 0; i < rowData.length; i++) {
                                // alert(i)
                                programid[i] = $('#table_list_1').jqGrid('getCell', rowData[i], 'group_programid');//name是colModel中的一属性

                                //if($('#table_list_1').jqGrid('getCell',rowData[i],'type')=="""")

                                var type1 = $('#table_list_1').jqGrid('getCell', rowData[i], 'devicetype');
                               
                                if (type1 ==  domain.language.$t('jiemu_sblx0')) {

                                    type = 0;
                                }
                                if (type1 ==  domain.language.$t('jiemu_sblx1')) {

                                    type = 1;
                                }

                                if (type1 ==  domain.language.$t('jiemu_sblx2')) {

                                    type = 2;
                                }




                                if (type1 ==  domain.language.$t('jiemu_sblx3')) {

                                    type = 3;
                                }


                                if (re_records == "" || re_records == null) {
                                    swal(domain.language.$t('jiemu_shehetishibiaoti'),domain.language.$t('jiemu_zwjmqxtj'), "info");
                                    return;
                                } else { 
                                    if (programid == "") {
                                        swal("OMG!",domain.language.$t('jiemu_qxxjmh'), "error");
                                        return false;

                                    }
                                }
                                //if(programid.indexOf("3")!=-1){

                                // swal("OMG!", "安卓节目,目前不能发送", "error");
                                //return false;
                                // }
                                // type = type.substring(0, type.length-1);
                                // alert(type);
                                //return;
                                //接口 /DeviceManagement/deviceCommand   参数  cmd 命令码47  devicenumber设备号，多个用逗号分隔，deviceType设备类型，programGroupId节目id，companyId 公司id
                                $("body").mLoading();
                                var coidval = $("#companyid").val();
                                if (coidval.indexOf(',') != -1) {
                                    coidval = coidval.split(',')[0];
                                }
                               
                               
                                    $("body").mLoading("show");
                                    
                                
                                $.ajax({
                                    type: 'POST',
                                    url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
                                    data: { cmd: 47, sessionid: sessionStorage.getItem("sid"), "programGroupId": parseInt(programid[i]) - 1, deviceType: type, "devicenumber": $("#device_id").val(), companyId: coidval },
                                    sessionid: sessionStorage.getItem("sid"),
                                    // timeout: 8000,//超时设置

                                    success: function (response) {
                                        response = JSON.parse(response);
                                        if (response.code == "200") {
                                           
                                         
                                            //alert("ii:"+ii+","+rowData.length)
                                             $(".mloading-mask").hide();
                                            // $("body").mLoading("hide");
                                         //   if (ii==0){ 
                                            
                                               swal("success!", domain.language.$t('jiemu_jmxjzqsd'), "success");
                                              $(".close").click();
                                         //   }
                                            cxlist();
                                             // ii++;
                                        } else {
                                           
                                            $("body").mLoading("hide")
                                            // $(".mloading-mask").hide();
                                            swal("OMG!",  domain.language.$t('jiemu_zlxfsb'), "error");
                                           
                                        }
                                    
                                    }, error: function (response, ajaxOptions, thrownError) {

                                      

                                        $("body").mLoading("hide")
                                        swal("OMG!",  domain.language.$t('jiemu_zlxfsb'), "error");
                                    },
                                    complete: function (XMLHttpRequest, status) {

                                        if (status == 'timeout') {
                                           

                                $("body").mLoading("hide")
                                            // swal("OMG!", "发送失败", "error");

                                        }
                                    }
                                });
                            }
                        }
                    }
                }
            }
        }
    });


    // $("#power").click(function(){
    // parent.addTabs({id:'108',title: '播放列表',close: true,url: '?#/page/Program/sendoption'});

    // });

   
});


//跳转到发送状态中
window.state = function (programid, devicetype) {

    sessionStorage.setItem("programid", programid);
    sessionStorage.setItem("deviceType", devicetype);
    //parent.addTabs({id:'104',title: '节目状态',close: true,url: '?#/page/Program/liststate'});

    $("#state").click();
    window.frames["iframescr"].window.cxlist();
    //   setTimeout(function(){
    // document.getElementById('iframescr').contentWindow.location.reload(true);
    //},500);

};


window.exportExcel=function(){
    var form = $("<form>");
   form.attr('style', 'display:none');
    form.attr('target', '');
    form.attr('method', 'post');
    form.attr('action', domain.testUrl +"/Threeinjection/exports?companyId="+parseInt(sessionStorage.getItem("coid"))+"&type="+parseInt(3)+"&language="+window.localStorage.getItem('languageval'));

    var input1 = $('<input>');
    input1.attr('type', 'hidden');
    input1.attr('name', 'item');
    input1.attr('value', 'test');     

    $('#excl').append(form);
    form.append(input1);
    
   form.submit();
   form.remove();    
}
